{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "plt.ion()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "datapath1 = \"/Users/aavattikutis/Documents/epidemicmodel/cccruns/fits/run1/\"\n",
    "datapath2 = \"/Users/aavattikutis/Documents/epidemicmodel/cccruns/fits/run2/\"\n",
    "models = [\"fulllinearmodel_fit_table.csv\",\"reducedlinearmodelNegBinom_fit_table.csv\",\n",
    "          \"reducedlinearmodelq0_fit_table.csv\",\"reducedlinearmodelq0ctime_fit_table.csv\"]\n",
    "\n",
    "model = models[-1]\n",
    "df = pd.read_csv(datapath2 + model)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#get roi\n",
    "rois = df.roi.unique()\n",
    "#get inferred\n",
    "theta = df.columns[2:] \n",
    "ntheta = len(theta)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-1-00775f99d2be>, line 28)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-1-00775f99d2be>\"\u001b[0;36m, line \u001b[0;32m28\u001b[0m\n\u001b[0;31m    ax.annotate(roi,-)\u001b[0m\n\u001b[0m                     ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#plot side by side \n",
    "\n",
    "def simpleaxis(ax):\n",
    "    ax.spines['top'].set_visible(False)\n",
    "    ax.spines['bottom'].set_visible(False)\n",
    "    ax.spines['right'].set_visible(False)\n",
    "    ax.spines['left'].set_visible(False)\n",
    "    \n",
    "import math\n",
    "def plot_table_data(df,rois):\n",
    "    fig, axes = plt.subplots(math.ceil(ntheta/3), 3, figsize=(20, 150))\n",
    "    for i, ax in enumerate(axes.flat):\n",
    "        try:\n",
    "            col = theta[i]\n",
    "            for j, roi in enumerate(rois):\n",
    "                boxes = [\n",
    "                    {\n",
    "                    'x': i,\n",
    "                    'label' : roi,\n",
    "                    'whislo': df.loc[(df.roi==roi)&(df['quantile']==0.025), col].values[0],    # Bottom whisker position\n",
    "                    'q1'    : df.loc[(df.roi==roi)&(df['quantile']==0.25), col].values[0],    # First quartile (25th percentile)\n",
    "                    'med'   : df.loc[(df.roi==roi)&(df['quantile']==0.5), col].values[0],    # Median         (50th percentile)\n",
    "                    'q3'    : df.loc[(df.roi==roi)&(df['quantile']==0.75), col].values[0],     # Third quartile (75th percentile)\n",
    "                    'whishi': df.loc[(df.roi==roi)&(df['quantile']==0.975), col].values[0],    # Top whisker position\n",
    "                    'fliers': []        # Outliers\n",
    "                    }\n",
    "                ]\n",
    "                ax.annotate(roi,-)\n",
    "                ax.bxp(boxes, positions=[j], showfliers=False, vert=False, patch_artist=True,\n",
    "                       boxprops=dict(facecolor='none',edgecolor='gray'))\n",
    "            ax.set_title(theta[i])\n",
    "            simpleaxis(ax)\n",
    "        except:\n",
    "            simpleaxis(ax)\n",
    "            ax.xaxis.set_visible(False)\n",
    "            ax.yaxis.set_visible(False)\n",
    "            \n",
    "roi_us = np.sort([i for i in rois if i[:2]=='US'])[::-1]\n",
    "roi_other = np.sort([i for i in rois if i[:2]!='US'])[::-1]\n",
    "rois = list(roi_us) + list(roi_other)\n",
    "print(rois)\n",
    "\n",
    "plot_table_data(df, rois)\n",
    "plt.subplots_adjust(hspace=0.2,wspace=1)\n",
    "plt.suptitle(model.split('.csv')[0])\n",
    "plt.savefig(\"../postfit_derivatives/\"+model.split('.csv')[0]+'_allroi.png')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
